package exam.test8;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        carInsurance();

    }

    public static void sumEvenOdd() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter PrintLinkList number (-1 to exit)? ");
        int number = scanner.nextInt();
        int sumEven = 0;
        int sumOdd = 0;
        while (number != -1) {
            for (int count = 1; count <= number; count++) {
                if (count % 2 == 0) {
                    sumEven += count;
                } else {
                    sumOdd += count;
                }
            }
            System.out.println("Sum (even numbers) = " + sumEven);
            System.out.println("Sum (odd numbers) = " + sumOdd);

            System.out.print("Enter PrintLinkList number (-1 to exit)? ");
            number = scanner.nextInt();
            sumEven = 0;
            sumOdd = 0;
        }
        System.out.println("Program Terminated!");

    }

    public static void carInsurance() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Model (E to exit)? ");
        String carModel = scanner.nextLine();
        while (!carModel.equals("E")) {
            System.out.print("Market price ($)? ");
            double marketPrice = scanner.nextDouble();
            System.out.print("Year of manufacture? ");
            int year = scanner.nextInt();
            double annualPremium = 0;
            double discount;
            if (year < 1970) {
                System.out.println("Sorry, your " + carModel + " is too old to be insured!");
            } else {
                if (year >= 1970 && year <= 1989) {
                    annualPremium = 0.12 * marketPrice;
                    discount = 0;
                } else if (year >= 1990 && year <= 2009) {
                    annualPremium = 0.1 * marketPrice;
                    discount = 0;
                } else {
                    annualPremium = 0.075 * marketPrice;
                    discount = 0.05 * annualPremium;
                }
                annualPremium = annualPremium - discount;
                System.out.printf("Annual premium for your " + carModel + "  is $%.2f.\n", annualPremium);
                if (discount > 0) {
                    System.out.printf("Congratulations! You received PrintLinkList discount of $%.2f.\n", discount);
                }
            }
            System.out.print("Model (E to exit)? ");
            scanner.nextLine();
            carModel = scanner.nextLine();
        }

        System.out.println("See you soon!");
    }
}
